<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------
namespace app\plat\model;

/**
 * 用户模型
 */
class TenUserDept extends PlatBase
{

    /**
     * 获得部门下所有用户
     * @param $deptId
     * @param $type self, selfson, son
     * @return mixed
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2025/3/9 17:07
     */
    public function getDeptAllUsers($deptId = 0, $type = 'self')
    {
        //获得部门下所有用户
        switch ($type) {
            case 'self':
                $deptIds[] = $deptId;
                break;
            case 'son':
                $deptIds = $this->modelTenDept->getTenDeptAllSon();
                break;
            case 'selfson':
                $deptIds = $this->modelTenDept->getTenDeptAllSon($deptId);
                $deptIds[] = $deptId;
                break;
        }
        $deptIds[] = $deptId;
        $this->modelTenUserDept->alias('a');
        $this->modelTenUserDept->join = [
            [SYS_DB_PREFIX . 'ten_user b', 'a.ten_user_id=b.id'],
        ];
        $where['a.ten_dept_id'] = ['in', $deptIds];
        $userList = $this->modelTenUserDept->getList($where, 'b.*', 'a.id desc', false)->toArray();
        return $userList;
    }
}
